﻿using NGrid.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Drivers;

namespace NGrid.Drivers
{
    public class NGridDriver : ContentPartDriver<NGridPart> 
    {
        protected override DriverResult Display(NGridPart part, string displayType, dynamic shapeHelper) 
        {
            return ContentShape("Parts_NGrid", () => shapeHelper.Parts_NGrid(EnablePaging: part.EnablePaging,
                                                                             EnableSorting: part.EnableSorting,
                                                                             TargetTableName: part.TargetTableName,
                                                                             PageSize: part.PageSize,
                                                                             PagePossibleSizes: part.PagePossibleSizes));
        }

        //GET
        protected override DriverResult Editor(NGridPart part, dynamic shapeHelper) 
        {
            return ContentShape("Parts_NGrid_Edit", () => shapeHelper.EditorTemplate(TemplateName: "Parts/NGrid",
                                                                                     Model: part,
                                                                                     Prefix: Prefix));
        }

        //POST
        protected override DriverResult Editor(NGridPart part, IUpdateModel updater, dynamic shapeHelper)
        {
            updater.TryUpdateModel(part, Prefix, null, null);
            return Editor(part, shapeHelper);
        }
    }
}